package com.jinke.api.modules.app.controller;


import com.jinke.api.common.api.CommonResult;
import com.jinke.api.modules.app.response.UploadResponse;
import com.jinke.api.modules.app.util.OssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@Api(tags = "附件管理")
@Tag(name = "附件管理", description = "附件管理")
@RequestMapping("/app/attachment")
public class AttachmentController {

    @Resource
    private OssUtil ossUtil;

    @ApiOperation("上传图片")
    @PostMapping(value = "/upload/image")
    @ResponseBody
    public CommonResult<UploadResponse> UploadImage(@RequestParam("file") MultipartFile file) {
        String url = ossUtil.upload(file);
        UploadResponse uploadResponse = new UploadResponse();
        uploadResponse.setUrl(url).setType("image").setId(0);
        if (!url.equals("")) {
            return CommonResult.success(uploadResponse);
        } else {
            return CommonResult.failed();
        }
    }

}
